﻿using UnityEngine;
using System.Collections;
namespace Room
{
    public class RCMoveSamplePosition : RCMoveBase
    {
        public RCMoveSamplePosition(RoomCharactor owner)
            :base(owner)
        {
            type = MoveType.SamplePosition;
        }

        public Vector3 srcPos;

        private bool sampled=false;

        public void Init(Vector3 srcPos)
        {
            this.srcPos = srcPos;
            owner.transform.position = srcPos;
        }
        public override void DoStart()
        {
            sampled = false;
        }

        public override void Tick()
        {
            if (sampled)
                return;
            NavMeshHit hit;
            //Vector3 p = srcPos;
            //p.y -= 10f;
            //NavMesh.Raycast(srcPos, p, out hit, NavMesh.AllAreas);
            if (NavMesh.SamplePosition(srcPos, out hit, 10f, NavMesh.AllAreas))
            {
                sampled = true;
                owner.transform.position = hit.position;
            }
        }
    }

}

